package com.redbox.RedboxManagment.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.redbox.RedboxManagment.ejb.Card;

@Repository(value = "cardDao")
public class CardImp extends HibernateDaoSupport implements ICard {
	
	
	@Transactional(readOnly = true)
	public Card findById(int pId) {
		
		String queryString= "from Card a where a.idCard=?";
		List<Card> result = getHibernateTemplate().find(queryString,pId);	
		
        if (result.size() > 0) {
            return result.get(0);
        } else {
            return null;
        }   
	}


	@Transactional
	public Card persistOnMerge(Card pCard) {
		Card result = (Card) getHibernateTemplate().save(pCard);
		return result;
	}

}
